/*
 * Cra.h
 *
 *  Created on: May 20, 2025
 *      Author: 86183
 */

#ifndef BSP_INC_CRA_H_
#define BSP_INC_CRA_H_


#include "main.h"
#include "delay.h"
#include "I2C.h"
#include "dcmi.h"


#define OV5640_ID                   0X5640  /* OV5640的芯片ID */
#define OV5640_ADDR                 0X78    /* OV5640的IIC地址 */

/* OV5640相关寄存器定义 */
#define OV5640_CHIPIDH              0X300A  /* OV5640芯片ID高字节 */
#define OV5640_CHIPIDL              0X300B  /* OV5640芯片ID低字节 */

/*
 * HAL库中硬件I2C的操作函数
 * HAL_I2C_GenerateSTART(&hi2c1, 100); // 100ms 超时
 * HAL_I2C_GenerateSTOP(&hi2c1, 100);
 * HAL_I2C_Master_SendNACK(&hi2c1);
 * uint8_t reg_addr = 0x12;
	HAL_I2C_Master_Transmit(&hi2c1, OV5640_ADDR, &reg_addr, 1, 100);
	uint8_t data;
	HAL_I2C_Master_Receive(&hi2c1, OV5640_ADDR, &data, 1, 100);

 */

uint8_t ov5640_read_reg(uint16_t reg);
HAL_StatusTypeDef ov5640_write_reg(uint16_t reg, uint8_t data);
void ov5640_flash_ctrl(uint8_t sw);
uint8_t OV5640_Init(void);
void ov5640_rgb565_mode(void);
uint8_t ov5640_focus_init(void);
uint8_t ov5640_focus_single(void);
void ov5640_brightness(uint8_t bright);
void ov5640_color_saturation(uint8_t sat);
void ov5640_contrast(uint8_t contrast);
void ov5640_sharpness(uint8_t sharp);
uint8_t ov5640_focus_constant(void);
uint8_t ov5640_outsize_set(uint16_t offx, uint16_t offy, uint16_t width, uint16_t height);

#endif /* BSP_INC_CRA_H_ */
